package org.xxpay.pay.channel.abcpay;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.xxpay.pay.channel.BaseService;

import javax.annotation.PostConstruct;

/**
 * @author: pangxiaoyu
 * @date: 2019年12月24日10:32:53
 * @description: 中国农行支付配置
 */
@Component
public class AbcpayConfig extends BaseService {

    private static String certPath;

    private static String logPath;

    @PostConstruct
    public void transValues() {
        AbcpayConfig.certPath = getCertRootPath();
        AbcpayConfig.logPath = getLogRootPath();
    }

    public static final String CHANNEL_NAME = "abcpay";

    public static final String CHANNEL_NAME_QR = CHANNEL_NAME + "_bank_qr";  // 农行网银支付
    public static final String CHANNEL_NAME_ALIPAY_QR = CHANNEL_NAME + "_alipay_qr"; // 农行支付宝扫码
    public static final String CHANNEL_NAME_ALIPAY_H5 = CHANNEL_NAME + "_alipay_h5"; // 农行支付宝H5
    public static final String CHANNEL_NAME_WXPAY_QR = CHANNEL_NAME + "_wxpay_qr"; // 农行微信扫码
    public static final String CHANNEL_NAME_WXPAY_H5 = CHANNEL_NAME + "_wxpay_h5"; // 农行微信H5

    public static final String PAY_TYPE_QR = "1";           //银联支付
    public static final String PAY_TYPE_ALIPAY_WX = "2";    //聚合码支付
    public static final String PAY_TYPE_ALIPAY_H5 = "3";    // 支付宝H5支付
    public static final String PAY_TYPE_WX_H5 = "4";    // 微信H5支付

    public static final Long PAY_ORDER_TIME_OUT = 6 * 60l;        // 订单超时时间，单位秒

    public static final String PAY_TYPE_ID = "ImmediatePay"; //直接支付
    public static final String COMMODITY_TYPE = "0202"; //商品种类 消费类
    public static final String CURRENCY_CODE = "156";   //交易币种 人民币
    public static final String INSTALLMENT_MARK = "0";  //分期标志 不分期
    public static final String NOTIFY_TYPE = "1";       //通知方式 服务器通知
    public static final String IS_BREAK_ACCOUNT = "0";  //是否分账 不分账

    public static final String RETURN_VALUE_SUCCESS = "SUCCESS";
    public static final String RETURN_VALUE_ERROR = "ERROR";

    // 商户ID
    private String merchantId;
    //商户证书
    private String pfx;
    //商户证书密码
    private String password;

    public AbcpayConfig(){}

    public AbcpayConfig(String payParam) {
        Assert.notNull(payParam, "init abcpay config error");
        JSONObject object = JSONObject.parseObject(payParam);
        this.merchantId = object.getString("merchantId");
        this.pfx = object.getString("pfx");
        this.password = object.getString("password");
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getPfx() {
        return pfx;
    }

    public void setPfx(String pfx) {
        this.pfx = pfx;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static String getCertPath() {
        return certPath;
    }

    public static String getLogPath() {
        return logPath;
    }

    public String getCertRootPath() {
        return payConfig.getCertRootPath();
    }

    public String getLogRootPath() {
        return payConfig.getLogRootPath();
    }
}
